/**
 * @file    yd1363_data.h
 * @brief   数据链路
 * @author  Liuwei
 * @version 1.0.1
 * @date    2023-05-17
 * 
 * @copyright Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version   <th>Author   <th>Description
 * <tr><td>2023-05-17 <td>1.0.1     <td>Liuwei   <td>首次创建
 * </table>
 */

#ifndef __YD1363_DATA_H_
#define __YD1363_DATA_H_

/* file includes -------------------------------------------------------------*/
#include <stdint.h>
/* cplusplus -----------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif

/* macro/define/typedef ------------------------------------------------------*/
#define SOI   0x7E
#define EOI   0x0D
#define YDT1363_DATA_SIZE        (512)

typedef struct 
{
    uint8_t soi;
    uint8_t ver;
    uint8_t addr;
    uint8_t cid1;
    uint8_t cid2;
    uint16_t len;
    uint16_t info;
    uint16_t crc;
    uint8_t eoi;
    uint8_t data_buf[YDT1363_DATA_SIZE];
}ydt1363_data_type;

/* variables -----------------------------------------------------------------*/

/*******************************************************************************
 * public API List
 ******************************************************************************/
uint16_t yd1636_calc_crc(uint8_t *data_buf , uint16_t data_len);
void byte_to_ascii(uint8_t byte ,uint8_t *p_buf);
void str_to_ascii(uint8_t *str , uint16_t len , uint8_t *p_buf);
uint8_t ascii_to_byte(uint8_t *p_buf);
uint16_t ascii_to_half_word(uint8_t *p_buf);
uint32_t ascii_to_word(uint8_t *p_buf);
uint8_t check_len_vaild(uint16_t recv_len);
void half_to_ascii(uint16_t half ,uint8_t *p_buf);
void word_to_ascii(uint32_t word ,uint8_t *p_buf);
uint16_t yd1363_calc_len(uint16_t len);

#ifdef __cplusplus
}
#endif

#endif  /* #ifndef __YD1363_DATA_H_ */
/********** Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD *********/
